//
//  ActivityVC.h
//  Movie
//
//  Created by huazi on 15/11/4.
//  Copyright © 2015年 huazi. All rights reserved.
//

#import "HomePageAdCell.h"
@interface HomePageAdCell()<UIScrollViewDelegate>
@property (nonatomic)BOOL isLoaded;
@end
@implementation HomePageAdCell
- (void)setSubviews {
    self.scrollView =[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, DeviceWidth, kScaleDeviceLength(180.0))];
    self.scrollView.backgroundColor =[UIColor colorWithHexString:kcolorViewBJ];
    self.scrollView.pagingEnabled =YES;
    self.scrollView.bounces =NO;
    self.scrollView.delegate =self;
    self.scrollView.showsHorizontalScrollIndicator =NO;
    [self.contentView addSubview:self.scrollView];
}
- (void)setDataCell:(id)model {
    self.model =model;
    NSArray *arrayAds =model;
    if (arrayAds==nil||arrayAds.count==0) return;
    if (self.isLoaded) {
        return ;
    }
    for (int i=0; i<arrayAds.count; i++) {
        UIImageView *imageAd =[[UIImageView alloc] initWithFrame:CGRectMake(DeviceWidth *i, 0, DeviceWidth, kScaleDeviceLength(180.0f))];
        [self.scrollView addSubview:imageAd];
        imageAd.tag =100+i;
        [imageAd setUserInteractionEnabled:YES];
        UITapGestureRecognizer *singletap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
        [imageAd addGestureRecognizer:singletap];
        [imageAd setImage:[UIImage imageNamed:@"banner"]];
//        [imageAd sd_setImageWithURL:[NSURL URLWithString:[arrayAds[i] objectForKey:@"logo"]] placeholderImage:kplaceholderImage];
    }
    self.bannerBj =[[BannerBJView alloc] initWithFrame:CGRectMake(0, kScaleDeviceLength(180.0f)-40, DeviceWidth, 40)];
    [self.contentView addSubview:self.bannerBj];
    self.bannerBj.labelTitle.text =@"头图的说明文字0";
    self.scrollView.contentSize =CGSizeMake(DeviceWidth *(arrayAds.count), kScaleDeviceLength(180.0f));
    self.isLoaded =YES;
    
}
- (void)singleTap:(UITapGestureRecognizer *)sender {
    NSArray *arrayAds =self.model;
    NSDictionary *dic=[arrayAds objectAtIndex:sender.view.tag -100];
    self.block(dic);
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    if (scrollView ==self.scrollView) {
        self.bannerBj.pageControl.currentPage =self.scrollView.contentOffset.x /DeviceWidth;
        self.bannerBj.labelTitle.text =[NSString stringWithFormat:@"头图的说明文字%li",self.bannerBj.pageControl.currentPage];
    }
}
@end
